%post -p /bin/sh
/usr/sbin/new-kernel-pkg --package kernel --install 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?

%posttrans -p /bin/sh
/usr/sbin/new-kernel-pkg --package kernel --mkinitrd --dracut --depmod --update 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?
/usr/sbin/new-kernel-pkg --package kernel --rpmposttrans 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?
if [ `uname -i` == "aarch64" ] &&
        [ -f /boot/EFI/grub2/grub.cfg ]; then
        /usr/bin/sh /usr/sbin/mkgrub-menu-6.6.0-28.0.0.34.sh 6.6.0-28.0.0.34.oe2403.aarch64  /boot/EFI/grub2/grub.cfg  update
fi
if [ `uname -i` == "loongarch64" ];then
        [ -f /etc/grub2.cfg ] && GRUB_CFG=`readlink -f /etc/grub2.cfg`
        [ "x${GRUB_CFG}" == "x" ] && [ -f /etc/grub2-efi.cfg ] && GRUB_CFG=`readlink -f /etc/grub2-efi.cfg`
        [ "x${GRUB_CFG}" == "x" ] && [ -f /boot/efi/EFI/openEuler/grub.cfg ] && GRUB_CFG=/boot/efi/EFI/openEuler/grub.cfg
        [ "x${GRUB_CFG}" != "x" ] && grub2-mkconfig -o ${GRUB_CFG}
        grubby --set-default=/boot/vmlinuz-6.6.0-28.0.0.34.oe2403.x86_64
fi
if [ -x /usr/sbin/weak-modules ]
then
    /usr/sbin/weak-modules --add-kernel 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?
fi
/usr/sbin/new-kernel-pkg --package kernel --mkinitrd --dracut --depmod --update 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?
/usr/sbin/new-kernel-pkg --package kernel --rpmposttrans 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?

%preun -p /bin/sh
if [ `uname -i` == "aarch64" ] &&
        [ -f /boot/EFI/grub2/grub.cfg ]; then
    /usr/bin/sh  /usr/sbin/mkgrub-menu-6.6.0-28.0.0.34.sh 6.6.0-28.0.0.34.oe2403.aarch64  /boot/EFI/grub2/grub.cfg  remove
fi

%postun -p /bin/sh
/usr/sbin/new-kernel-pkg --rminitrd --rmmoddep --remove 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?
if [ -x /usr/sbin/weak-modules ]
then
    /usr/sbin/weak-modules --remove-kernel 6.6.0-28.0.0.34.oe2403.x86_64 || exit $?
fi

# remove empty directory
if [ -d /lib/modules/6.6.0-28.0.0.34.oe2403.x86_64 ] && [ "`ls -A  /lib/modules/6.6.0-28.0.0.34.oe2403.x86_64`" = "" ]; then
    rm -rf /lib/modules/6.6.0-28.0.0.34.oe2403.x86_64
fi
if [ `uname -i` == "loongarch64" ];then
        [ -f /etc/grub2.cfg ] && GRUB_CFG=`readlink -f /etc/grub2.cfg`
        [ "x${GRUB_CFG}" == "x" ] && [ -f /etc/grub2-efi.cfg ] && GRUB_CFG=`readlink -f /etc/grub2-efi.cfg`
        [ "x${GRUB_CFG}" == "x" ] && [ -f /boot/efi/EFI/openEuler/grub.cfg ] && GRUB_CFG=/boot/efi/EFI/openEuler/grub.cfg
        [ "x${GRUB_CFG}" != "x" ] && grub2-mkconfig -o ${GRUB_CFG}
fi
